//
//  AroundShopFilterView.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/18.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "AroundShopFilterView.h"

@interface AroundShopFilterView ()

@property (nonatomic, strong) UIButton *filter1;
@property (nonatomic, strong) UIButton *filter2;
@property (nonatomic, strong) UIButton *filter3;
@property (nonatomic, strong) UIButton *filter4;
@property (nonatomic, strong) UIButton *filter5;

@property (weak, nonatomic) UIButton *selectedFilter;

@end

@implementation AroundShopFilterView

- (void)filterAction:(UIButton *)sender
{
    self.selectedFilter.selected = NO;
    sender.selected = YES;
    self.selectedFilter = sender;
    if (self.filterHandler) {
        if (sender == self.filter1) {
            self.filterHandler(@"");
        }
        if (sender == self.filter2) {
            self.filterHandler(@"1");
        }
        if (sender == self.filter3) {
            self.filterHandler(@"3");
        }
        if (sender == self.filter4) {
            self.filterHandler(@"4");
        }
        if (sender == self.filter5) {
            self.filterHandler(@"2");
        }
    }
    
}

- (void)setupSubViews
{
    self.filter1 = [[UIButton alloc] init];
    [self.filter1 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    [self.filter1 setTitleColor:kColor666666 forState:UIControlStateNormal];
    self.filter1.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filter1 setTitle:@"全部" forState:UIControlStateNormal];
    self.filter1.selected = YES;
    self.selectedFilter = self.filter1;
    [self.filter1 addTarget:self action:@selector(filterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.filter1];
    
    self.filter2 = [[UIButton alloc] init];
    [self.filter2 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    [self.filter2 setTitleColor:kColor666666 forState:UIControlStateNormal];
    self.filter2.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filter2 setTitle:@"直营店" forState:UIControlStateNormal];
    [self.filter2 addTarget:self action:@selector(filterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.filter2];
    
    self.filter3 = [[UIButton alloc] init];
    [self.filter3 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    [self.filter3 setTitleColor:kColor666666 forState:UIControlStateNormal];
    self.filter3.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filter3 setTitle:@"合作商" forState:UIControlStateNormal];
    [self.filter3 addTarget:self action:@selector(filterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.filter3];
    
    self.filter4 = [[UIButton alloc] init];
    [self.filter4 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    [self.filter4 setTitleColor:kColor666666 forState:UIControlStateNormal];
    self.filter4.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filter4 setTitle:@"加盟店" forState:UIControlStateNormal];
    [self.filter4 addTarget:self action:@selector(filterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.filter4];
    
    self.filter5 = [[UIButton alloc] init];
    [self.filter5 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    [self.filter5 setTitleColor:kColor666666 forState:UIControlStateNormal];
    self.filter5.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filter5 setTitle:@"供应商" forState:UIControlStateNormal];
    [self.filter5 addTarget:self action:@selector(filterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.filter5];
    
}

- (void)setupConstraints
{
    [self.filter1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self);
    }];
    
    [self.filter2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.filter1.mas_right);
        make.top.bottom.equalTo(self);
        make.width.equalTo(self.filter1);
    }];
    
    [self.filter3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.filter2.mas_right);
        make.top.bottom.equalTo(self);
        make.width.equalTo(self.filter1);
    }];
    
    [self.filter4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.filter3.mas_right);
        make.top.bottom.equalTo(self);
        make.width.equalTo(self.filter1);
    }];
    
    [self.filter5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.filter4.mas_right);
        make.top.right.bottom.equalTo(self);
        make.width.equalTo(self.filter1);
    }];
}

@end
